package cn.bdqn.t354.controller;

import cn.bdqn.t354.pojo.SysUser;
import cn.bdqn.t354.service.SysUserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class UserController {
    @Resource
    SysUserService sysUserService;

    @RequestMapping("/dologin")
    public String dologin(String usrName, String usrPassword,
                          Model model, HttpSession session){
        SysUser sysUser = sysUserService.login(usrName, usrPassword);
        if(sysUser!=null){
            session.setAttribute("loginUser",sysUser);
            return "main";
        }else{
            model.addAttribute("message","用户名或者密码错误");
            return "login";
        }

    }

    @RequestMapping("/user/list")
    public String findUsers(Model model){
        List<SysUser> list = sysUserService.findAllUsers();
        model.addAttribute("users",list);

        return "user/list";

    }

}
